#@head("操作日志列表")
#define main()
#end
<body>
	<div class="layui-fluid">
		<div class="layui-row layui-col-space15">
			<div class="layui-col-md12">
				<div class="layui-card">
					<div class="layui-form layui-card-header layuiadmin-card-header-auto">
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label">日期范围</label>
								<div class="layui-input-inline">
									<input type="text" name="attr.create_time" class="layui-input" id="log-laydate-range-date" placeholder=" - ">
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">类型</label>
								<div class="layui-input-block">
									<select name="attr.log_type">
										<option value="">-请选择-</option>
										<option value="1">数据</option>
										<option value="2">系统</option>
									</select>
								</div>
							</div>
							<div class="layui-inline">
								<button class="layui-btn layuiadmin-btn-menu" lay-submit lay-filter="LAY-log-front-search">查询</button>
							</div>
						</div>
					</div>
					<div class="layui-card-body">
						<div style="padding-bottom: 10px;">
							<button class="layui-btn layuiadmin-btn-menu" data-type="batchdel">删除</button>
							<button class="layui-btn layuiadmin-btn-menu" data-type="clear">清空</button>
						</div>
						<table id="LAY-system-log-manage" lay-filter="LAY-system-log-manage">
						</table>
						<script type="text/html" id="table-system-log-operate">
							<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail"><i class="layui-icon layui-icon-read"></i>查看</a>
			  			</script>
					</div>
				</div>
			</div>
		</div>
	</div>
	#@layui()
	#define use()
		use(["index", "form", "table", "laydate"], function(){
			var $ = layui.$,
			form = layui.form,
			table = layui.table,
			laydate = layui.laydate,
			a = layui.admin;
			
			table.render({
		        elem: "#LAY-system-log-manage",
		        url: layui.setter.base + "/system/log/list",
		        cellMinWidth: 80,
		        cols: [[
			        {type: "checkbox", fixed: "left"},
			        {field: "id", title: "ID", width: 80},
			        {field: "create_time", title: "操作时间", width: 200, sort: !0},
			        {field: "create_name", title: "操作人", width: 120},
			        {field: "log_type", title: "类型", width: 100, templet: function(d){
			        	if(d.log_type == 1){
			        		return "数据";
		                }else if(d.log_type == 2){
		                	return "系统";
		                }
			        }},
			        {field: "descript", title: "描述", templet: "<div>{{d.oper_object}}模块{{d.oper_type}}了主键为{{d.oper_id}}的数据</div>"},
			        {title: "操作", width: 200, align: "center", fixed: "right", toolbar: "#table-system-log-operate"}
		        ]],
		        page: {
			        layout: ["limit", "count", "prev", "page", "next", "skip"], //自定义分页布局
			        groups: 1, //只显示 1 个连续页码
			        first: false, //不显示首页
			        last: false //不显示尾页
		        },
		        limit: 20,
		        height: "full-220",
		        skin: "row", //行边框风格
		        even: true, //开启隔行背景
		        text: {
		            none: "暂无相关数据"
		        }
		    }),
		    table.on("tool(LAY-system-log-manage)", function(e) {
		        var data = e.data;
		        if ("detail" === e.event) {
		            layer.open({
		                type: 2,
		                title: "日志明细",
		                content: layui.setter.base + "/system/log/view?id=" + data.id,
		                maxmin: true,
		                area: ["450px", "400px"],
		                btn: ["确定"],
		                yes: function(e, t) {
		                	layer.close(e);
		                }
		            })
		        }
		    });
			
			//监听搜索
			form.on("submit(LAY-log-front-search)", function(data){
				var field = data.field;
				//执行重载
				table.reload("LAY-system-log-manage", {
					where: field
				});
			});
			
			//事件
			var active = {
				batchdel: function(){
					var checkStatus = table.checkStatus("LAY-system-log-manage"),
					checkData = checkStatus.data;
					if(checkData.length === 0){
						return layer.msg("请选择数据");
					}
					var ids = new Array();
					if(checkData.length>0){
						for(var i=0; i < checkData.length; i++){
							ids.push(checkData[i].id);
						}
					}
					layer.confirm("确定删除吗？", function(e) {
						a.req({
							url: layui.setter.base + "/system/log/delete",
							data: {"ids": ids.join(",")},
							done: function(res){
								layer.msg(res.msg);
								table.reload("LAY-system-log-manage");
								layer.close(e);
							}
						});
					});
				},
				clear: function(){
					layer.confirm("确认要清空日志数据吗？", function(e) {
		            	a.req({
				            url: layui.setter.base + "/system/log/clearLog",
		                    done: function(res){
		            			layer.msg(res.msg);
		   						table.reload("LAY-system-log-manage");
		                        layer.close(e)
		   					}
				        });
		            });
				}
			};
			
			$(".layui-btn.layuiadmin-btn-menu").on("click", function(){
				var type = $(this).data("type");
				active[type] ? active[type].call(this) : "";
			});
			
			//日期范围
			laydate.render({
				elem: "#log-laydate-range-date",
				theme: "grid",
				range: true
			});
		});
	#end
</body>
</html>
